#include <bits/stdc++.h>
using namespace std;
vector<int> nums;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, h;
    cin >> x >> h;
    nums.push_back(h);
  }

  vector<int> tails;

  for (int num : nums) {
    //这里是严格上升，所以用upper_bound
    //如果是非严格上升，就用lower_bound
    auto it = upper_bound(tails.begin(), tails.end(), num);
    if (it == tails.end()) {
      tails.push_back(num);
    } else {
      *it = num;
    }
  }

  cout << tails.size();

  return 0;
}
